﻿<%@ Page Title="Quản lý lớp học - Sen Quốc Tế" Language="C#" MasterPageFile="~/Admin/AdminMTP.Master" AutoEventWireup="true" CodeBehind="Class_Manager.aspx.cs" Inherits="SQT.tracnghiem.Admin.Class_Manager" %>

<%@ Import Namespace="DataAccess" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Content/css/educate.css" rel="stylesheet" />
    <script src="../Scripts/javacuatui3.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="w3-row">
        <div class="w3-third w3-padding">
            <span class="w3-teal letter-search-btn" title="Tìm kiếm"><i class="fa fa-search"></i></span>
            <input type="text" id="find_class" placeholder="Nhập tên lớp" class="search-input" />
        </div>
        <div class="w3-third w3-padding">
            <a onclick="document.getElementById('themlop').style.display = 'block'" class="w3-btn w3-teal"><i class="fa fa-plus"></i>&nbsp;<i class="fa fa-graduation-cap"></i>&nbsp;Thêm lớp</a>
            <a onclick="document.getElementById('nhaplop').style.display = 'block'" class="w3-btn w3-teal"><i class="fa fa-retweet"></i>&nbsp;<i class="fa fa-graduation-cap"></i>&nbsp;Nhập lớp</a>
        </div>
    </div>
    <div class="w3-responsive">
        <table id="class_show" class="staff-table w3-table w3-striped w3-white w3-bordered w3-border w3-small">
            <tr class="w3-teal">
                <th>Lớp</th>
                <th>Giáo viên</th>
                <th>Ngày khai giảng</th>
                <th>Ngày tốt nghiệp</th>
                <th>Hình thức</th>
                <th>Lịch học</th>
                <th>Sáng</th>
                <th>Chiều</th>
                <th>Tối</th>
                <th>Trình độ</th>
                <th>Bài học</th>
            </tr>
            <% var get_cls = (from p in new TblClassController().FetchAll().Where(x=>x.Active==true) orderby p.Id descending select p);
               foreach (TblClass cls in get_cls)
               {
                   if (cls.Id == 0)
                       continue;
                   var get_teacher = new TblManagerController().FetchAll().Where(x => x.ManagerId == cls.Teacher).Single();

                   string time = "";
                   string temp = cls.Schedule;
                   string[] split = new string[7];
                   split = temp.Split(',');
                   for (int i = 0; i < temp.Split(',').Length - 1; i++)
                   {
                       if (split[i] != "")
                       {
                           int temp2 = int.Parse(split[i]) + 1;
                           if (temp2 == 1)
                               time += " Thứ 2";
                           else
                               time += " Thứ " + temp2;
                           if (split[i + 1] != "")
                               time += ",";
                       }
                   }

                   string morning = "", afternoon = "", evening = "";
                   temp = cls.TimeStudy;
                   split = temp.Split(',');
                   string[] split2 = new string[2];
                   if (split[0] != "")
                   {
                       split2 = split[0].Split('_');
                       morning = split2[0] + " - " + split2[1];
                   }
                   if (split[1] != "")
                   {
                       split2 = split[1].Split('_');
                       afternoon = split2[0] + " - " + split2[1];
                   }
                   if (split[2] != "")
                   {
                       split2 = split[2].Split('_');
                       evening = split2[0] + " - " + split2[1];
                   }

                   string open = "", close = "";
                   if (cls.OpenDate != null)
                       open = DateTime.Parse(cls.OpenDate.ToString()).Day + "/" + DateTime.Parse(cls.OpenDate.ToString()).Month + "/" + DateTime.Parse(cls.OpenDate.ToString()).Year;
                   if (cls.CloseDate != null)
                       close = DateTime.Parse(cls.CloseDate.ToString()).Day + "/" + DateTime.Parse(cls.CloseDate.ToString()).Month + "/" + DateTime.Parse(cls.CloseDate.ToString()).Year;
            %>
            <tr class="class-options">
                <td class="class_id w3-hide"><%=cls.Id %></td>
                <td><%
                       if (DateTime.Parse(cls.OpenDate.ToString()).Date > DateTime.Now)
                       {%>
                    <i title="Sắp mở" class="w3-tiny fa fa-circle w3-text-blue"></i>
                    <%}
                       else
                       {
                           if (cls.Active == true)
                           { %>
                    <i title="Đang mở" class="w3-tiny fa fa-circle w3-text-green"></i>
                    <%}
                           else
                           {%>
                    <i title="Đã đóng" class="w3-tiny fa fa-circle w3-text-red"></i>
                    <%}
                       } %>&nbsp;<%=cls.ClassName %>
                </td>
                <td><%=get_teacher.FullName %></td>
                <td><%=open%></td>
                <td><%=close %></td>
                <td><%=cls.Degree %></td>
                <td><%=time %></td>
                <td><%=morning %></td>
                <td><%=afternoon %></td>
                <td><%=evening %></td>
                <td><%=cls.ClsLevel %></td>
                <td><%=cls.Lesson %></td>
            </tr>
            <%} %>

            <% var get_cls2 = (from p in new TblClassController().FetchAll().Where(x=>x.Active==false) orderby p.Id descending select p);
               foreach (TblClass cls in get_cls2)
               {
                   if (cls.Id == 0)
                       continue;
                   var get_teacher = new TblManagerController().FetchAll().Where(x => x.ManagerId == cls.Teacher).Single();

                   string time = "";
                   string temp = cls.Schedule;
                   string[] split = new string[7];
                   split = temp.Split(',');
                   for (int i = 0; i < temp.Split(',').Length - 1; i++)
                   {
                       if (split[i] != "")
                       {
                           int temp2 = int.Parse(split[i]) + 1;
                           if (temp2 == 1)
                               time += " Thứ 2";
                           else
                               time += " Thứ " + temp2;
                           if (split[i + 1] != "")
                               time += ",";
                       }
                   }

                   string morning = "", afternoon = "", evening = "";
                   temp = cls.TimeStudy;
                   split = temp.Split(',');
                   string[] split2 = new string[2];
                   if (split[0] != "")
                   {
                       split2 = split[0].Split('_');
                       morning = split2[0] + " - " + split2[1];
                   }
                   if (split[1] != "")
                   {
                       split2 = split[1].Split('_');
                       afternoon = split2[0] + " - " + split2[1];
                   }
                   if (split[2] != "")
                   {
                       split2 = split[2].Split('_');
                       evening = split2[0] + " - " + split2[1];
                   }

                   string open = "", close = "";
                   if (cls.OpenDate != null)
                       open = DateTime.Parse(cls.OpenDate.ToString()).Day + "/" + DateTime.Parse(cls.OpenDate.ToString()).Month + "/" + DateTime.Parse(cls.OpenDate.ToString()).Year;
                   if (cls.CloseDate != null)
                       close = DateTime.Parse(cls.CloseDate.ToString()).Day + "/" + DateTime.Parse(cls.CloseDate.ToString()).Month + "/" + DateTime.Parse(cls.CloseDate.ToString()).Year;
            %>
            <tr class="class-options">
                <td class="class_id w3-hide"><%=cls.Id %></td>
                <td><%
                       if (DateTime.Parse(cls.OpenDate.ToString()).Date > DateTime.Now)
                       {%>
                    <i title="Sắp mở" class="w3-tiny fa fa-circle w3-text-blue"></i>
                    <%}
                       else
                       {
                           if (cls.Active == true)
                           { %>
                    <i title="Đang mở" class="w3-tiny fa fa-circle w3-text-green"></i>
                    <%}
                           else
                           {%>
                    <i title="Đã đóng" class="w3-tiny fa fa-circle w3-text-red"></i>
                    <%}
                       } %>&nbsp;<%=cls.ClassName %>
                </td>
                <td><%=get_teacher.FullName %></td>
                <td><%=open%></td>
                <td><%=close %></td>
                <td><%=cls.Degree %></td>
                <td><%=time %></td>
                <td><%=morning %></td>
                <td><%=afternoon %></td>
                <td><%=evening %></td>
                <td><%=cls.ClsLevel %></td>
                <td><%=cls.Lesson %></td>
            </tr>
            <%} %>
        </table>
    </div>
    <div id="themlop" class="w3-modal" style="padding-top: 40px">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal w3-padding" style="width: 50%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-large">Thêm lớp mới</p>
            </header>
            <div class="w3-padding-bottom w3-row">
                <label class="w3-quarter">Tên lớp</label><input type="text" id="add_class_name" required="required" placeholder="Nhập tên lớp" autofocus="autofocus" class="class-editor w3-half" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Giáo viên</label>
                <select id="add_class_teacher" class="class-editor w3-half">
                    <%foreach (TblManager teacher in new TblManagerController().FetchAll().Where(x => x.Role == 2))
                      { %>
                    <option value="<%=teacher.ManagerId %>"><%=teacher.FullName %></option>
                    <%} %>
                </select>
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Ngày mở</label>
                <input id="add_class_open" type="date" required="required" autofocus="autofocus" class="class-editor w3-half" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Ngày đóng</label>
                <input id="add_class_close" type="date" required="required" autofocus="autofocus" class="class-editor w3-half" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Hình thức</label>
                <input id="add_class_type" type="text" required="required" autofocus="autofocus" placeholder="Nhập hình thức học" class="class-editor w3-half" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Lịch học</label>
                <div class="checkbox w3-half">
                    <input type="checkbox" value="thu2" id="monday" /><label for="monday">Thứ 2</label>&nbsp;
                            <input type="checkbox" value="thu3" id="tuesday" /><label for="tuesday">Thứ 3</label>&nbsp;
                            <input type="checkbox" value="thu4" id="wednesday" /><label for="wednesday">Thứ 4</label><br />
                    <input type="checkbox" value="thu5" id="thursday" /><label for="thursday">Thứ 5</label>&nbsp;
                            <input type="checkbox" value="thu6" id="friday" /><label for="friday">Thứ 6</label>&nbsp;
                            <input type="checkbox" value="thu7" id="saturday" /><label for="saturday">Thứ 7</label>
                </div>
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Sáng</label><input id="add_morning_from" type="time" class="class-editor w3-col l3" /><label class="w3-col l2 w3-padding">Đến</label><input id="add_morning_to" type="time" class="class-editor w3-col l3" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Chiều</label><input id="add_afternoon_from" type="time" class="class-editor w3-col l3" /><label class="w3-col l2 w3-padding">Đến</label><input id="add_afternoon_to" type="time" class="class-editor w3-col l3" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <label class="w3-quarter">Tối</label><input id="add_evening_from" type="time" class="class-editor w3-col l3" /><label class="w3-col l2 w3-padding">Đến</label><input id="add_evening_to" type="time" class="class-editor w3-col l3" />
            </div>
            <div class="w3-padding-bottom w3-row">
                <label class="w3-quarter">Bài học</label><textarea id="add_class_lesson" required="required" placeholder="Nhập bài đang học" autofocus="autofocus" class="class-editor w3-half" cols="3"></textarea>
            </div>
            <div class="w3-padding-bottom w3-row">
                <label class="w3-quarter">Trình độ</label><input id="add_class_level" type="text" required="required" placeholder="Nhập trình độ" autofocus="autofocus" class="class-editor w3-half" />
            </div>
            <div class="w3-row w3-padding-bottom w3-center">
                <a class="btn_add_class w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            </div>
        </div>
    </div>
    <div id="sualop" class="w3-modal">
    </div>
    <div id="xoalop" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 45%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Bạn có chắc chắn muốn xóa lớp này ?</p>
            </header>
            <div class="w3-row w3-padding w3-center">
                <a class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-trash"></i>&nbsp;Xóa</a>
                <a onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-times"></i>&nbsp;Hủy</a>
            </div>
        </div>
    </div>
    <%var merge_class = (from p in new TblClassController().FetchAll() orderby p.Id descending where p.Active == true select p); %>
    <div id="nhaplop" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 50%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Nhập lớp</p>
            </header>
            <div class="w3-padding w3-row">
                <label class="w3-quarter">Từ lớp</label>
                <select id="merge_class_from" class="w3-half" style="padding: 0.5%; color: black">
                    <%foreach (TblClass cls in merge_class)
                      {
                          if (cls.Id == 0)
                              continue;
                          var get_teacher = new TblManagerController().FetchAll().Where(x => x.ManagerId == cls.Teacher).Single();
                    %>
                    <option value="<%=cls.Id %>"><%=cls.ClassName %> - <%=get_teacher.FullName %></option>
                    <%} %>
                </select>
            </div>
            <div class="w3-padding w3-row">
                <label class="w3-quarter">Vào lớp</label>
                <select id="merge_class_to" class="w3-half" style="padding: 0.5%; color: black">
                    <%foreach (TblClass cls in merge_class)
                      {
                          if (cls.Id == 0)
                              continue;
                          var get_teacher = new TblManagerController().FetchAll().Where(x => x.ManagerId == cls.Teacher).Single();
                    %>
                    <option value="<%=cls.Id %>"><%=cls.ClassName %> - <%=get_teacher.FullName %></option>
                    <%} %>
                </select>
            </div>
            <div class="w3-row w3-padding w3-center">
                <a onclick="document.getElementById('merge_class').style.display='block'" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-save"></i>&nbsp;Đồng ý</a>
            </div>
        </div>
    </div>
    <div id="merge_class" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-deep-orange" style="width: 50%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-large">Thông tin lớp cũ sẽ bị xóa, bạn có chắc chắn không?</p>
            </header>
            <div class="w3-row w3-padding w3-center">
                <a class="btn_merge_class w3-btn w3-red w3-border w3-border-white"><i class="fa fa-check"></i>&nbsp;Có</a>
                <a onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-btn w3-blue w3-border w3-border-white"><i class="fa fa-times"></i>&nbsp;Không</a>
            </div>
        </div>
    </div>
</asp:Content>
